Skip to content

id(world_net): make inbound_refusal_backpressures test deterministic (#5195) - #5215

Merged
dezren39 merged 1 commit into
mainfrom
fix/5195-inbound-refusal-flake
Nov 4, 2026
Merged

dezren39 merged 1 commit into
mainfrom
fix/5195-inbound-refusal-flake

Conversation

@dezren39

@dezren39 dezren39 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Fixes #5195.

Root cause (the flake)

The test set BucketLimits { frames_per_sec: 1_000, frame_burst: 1, bytes_per_sec: 1_000, byte_burst: 1 }. In the evaluator's milli-token buckets (src/abuse.rs), that is a 1_000 milli-token capacity refilling at 1_000 milli-tokens per millisecond: after the first pre-auth charge drains the bucket, a full token is back after 1 ms of wall time. The shed assertion — second pre-auth charge must be refused — therefore only holds if the test thread runs the second charge within the same ~1 ms. Any scheduling stall ≥ 1 ms between the two charges (parallel full-suite load, sandbox CPU throttling) admits the second charge, charge_inbound_frame returns true, and the test panics with "a pre-auth refusal sheds the stream". A timing assumption in the test, not a backpressure race: the lib path (refill, refusal, retry clamp) behaves exactly as designed at every step.

The fix (test-only, pkgs/id/src/world_net.rs)

  • Rates drop to 1 token/sec (burst still 1) for both bucket kinds. A drained bucket now stays empty for ~1 s, so the shed leg holds with ~1000x margin over scheduler jitter. The authorized leg is unchanged in shape and duration: its refusal sleeps the existing 1 s retry floor (RETRY_FLOOR_MS) and then charges against the refilled bucket — ~1 s total, inside the existing 3 s bound.
  • The two previously bare first-charge awaits are now wrapped in 5 s tokio::time::timeouts with loud expects, so every await in the test is bounded: a wedged charge fails loudly in seconds instead of stalling a suite (relevant in the nix check phase, where the laptop sets max-silent-time = 0).
  • No lib change: the evaluator, buckets, and charge_inbound_frame are untouched, and the assertions still verify the same behavior — pre-auth refusal sheds immediately, authorized refusal waits out the refill and admits.

Hang verdict (switch incident)

Not this test, on the evidence. Pre-fix, the unmodified test ran 450 times on the laptop with zero failures and zero hangs (240 isolated across 6 parallel streams, 60 pinned to one CPU with two busy hogs, 150 under 32-way CPU saturation). Code audit agrees: every wait in the test's path is a tokio sleep of a refusal delay clamped to [1 s, 60 s] by Refusal::new, the two substantive second charges are already wrapped in 500 ms / 3 s timeouts, and the only unbounded awaits were the first charges against a fresh, full bucket (now bounded by this PR as well). A binary sitting single-threaded at 0 CPU for 52 minutes is far more consistent with an unbounded network await elsewhere in a check-phase suite (the id lib binary also carries live-iroh tests whose connects/receives have no outer timeout) than with this bounded test. The 52-minute hang remains unattributed — it is not evidence against this test, and this PR does not claim to fix it.

Verification

  • Post-fix: 101/101 runs of the named test pass (1 single + 40 under 32-way CPU saturation + 60 across 6 parallel streams on the loaded laptop), each ~1.0 s, none wedged.
  • Family context on the fixed binary: world_net::tests 22/22, abuse::tests 12/12, frames::tests 5/5.
  • Edited region is rustfmt-clean (edition 2024); the file's pre-existing fmt drift elsewhere is untouched.

Observed while reproducing (separate, not fixed here)

Full-lib host runs currently abort in cli::tests::module_trust_keys_are_repeatable_and_require_world_mode — unbounded stack recursion (overflows even with RUST_TEST_THREAD_STACK_SIZE=67108864), reproduced on several pre-existing primary-built lib binaries. It passes in the nix sandbox per the #5195 record, so it reads as a host-environment trigger. Filed as #5216.

…5195)

The shed leg raced the token-bucket refill: at 1_000 tokens/sec with a burst of 1, the drained bucket refills its single token in 1 ms, so any >= 1 ms scheduling stall between the two pre-auth charges admitted the second charge and failed "a pre-auth refusal sheds the stream" under load. Drop the test rates to 1 token/sec (burst still 1): the shed window becomes ~1 s, three orders of magnitude above scheduler jitter, while the authorized leg still completes in ~1 s inside its 3 s bound. Also bound the two previously bare first-charge awaits at 5 s so every await in the test fails loudly instead of stalling the suite. Test-only change; evaluator behavior untouched.
@dezren39
dezren39 requested a review from a team as a code owner November 4, 2026 00:19
@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f454798f-2ad1-41e4-b607-848ddbb3492c
Commits

Reviewing files that changed from the base of the PR and between 3adad8f and bdf4899.

Files selected for processing: 1
  • pkgs/id/src/world_net.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T00:20:23.188178Z bdf4899 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id(world_net): inbound_refusal_backpressures test is flaky — intermittent "a pre-auth refusal sheds the stream"

1 participant